package vn.allmobile.newsreader.adapters;

import java.util.List;

import vn.allmobile.newsreader.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.BaseAdapter;
import android.widget.ImageView;


public class NewsDetailAdapter extends BaseAdapter {
	WebView mWebView;
	List<Bitmap> mListBitmap;

	public NewsDetailAdapter(WebView webView) {
		this.mWebView = webView;
		// View v = mWebView;
		// v.setDrawingCacheEnabled(true);
		//
		// // cheat to force webview to draw itself
		// v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
		// MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
		// v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
		// v.buildDrawingCache(true);
		// Bitmap b = Bitmap.createBitmap(v.getDrawingCache());

		// Picture picture = mWebView.capturePicture();
		// Bitmap b = Bitmap.createBitmap(picture.getWidth(),
		// picture.getHeight(),
		// Bitmap.Config.ARGB_8888);
		// this.mListBitmap = new ArrayList<Bitmap>();
		// this.mListBitmap.add(b);
		// // v.setDrawingCacheEnabled(false); // clear drawing cache
		// // /
		// mWebView.scrollTo(0, 500);
		// picture = mWebView.capturePicture();
		// b = Bitmap.createBitmap(picture.getWidth(), picture.getHeight(),
		// Bitmap.Config.ARGB_8888);
		// this.mListBitmap.add(b);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mListBitmap.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.mListBitmap.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View mView = convertView;
		if (position == 0) {

		}
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) parent.getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			mView = inflater.inflate(
					R.layout.news_detail, null);
		}
		ImageView img = (ImageView) mView.findViewById(R.id.imgView);
		img.setImageBitmap(this.mListBitmap.get(position));
		return mView;
	}

}
